﻿import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import './pointsdetails.scss'
import cat04 from '../../assets/kedouimg01/sckf.png'
import xl from '../../assets/kedouimg01/xl.png'
import goto from '../mall/images/goto01.png'

export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
		resdata:[],
		result:[],
		pageNumber:0,
		money:0,
		navindex:1,
		islisyr:0,
		createDateEnd:'',
		appmark:CommonJs.getmark(),
    }
  }
  config = {
    navigationBarTitleText: '加载中'
  }
  componentWillMount () {
	if(this.state.appmark=='xjzb'){
		Taro.setNavigationBarTitle({title:'共享金'})
	}
	else{
		Taro.setNavigationBarTitle({title:'收益金'})
	}
	var money =this.$router.preload.money;
	this.setState({
		money:money
	  })
	this.getalldate()
	this.getdate(0)
  }
  componentDidShow () {
  	
  }
	getalldate(){
		var _this = this;
		var url = '/crm/papi/v1.9/currency?assetType=GXJ'
		CommonJs.ajaxRequest(url,'','GET',function(res){
			if (res.data.length>0) {
				var resdata = _this.state.resdata
				resdata = res.data[0]
				  _this.setState({
					resdata: resdata,
				  })     
			  } 
			},"wfw")
	}
  opendetails(url){
      this.$preload({
        regType:2
      })
      CommonJs.openTo(url)
	}
  getdate(pageNumber){
	var _this=this
	if(_this.state.createDateEnd != ''){
		var url = '/crm/papi/v1.9/currency?assetType=GXJ'+ '&createDateEnd=' + _this.state.createDateEnd
	}else{
		var url = '/crm/papi/v1.9/currency?assetType=GXJ'
	}
	var dates={}
	var type=this.state.navindex;
	if(type==1){
		dates.inOrOut=true
	}
	else{
		dates.inOrOut=false
	}
	CommonJs.ajaxRequest(url,dates,'GET',function(res){
		if (res.data.length>0) {
			var results = _this.state.result  
			var result = res.data[0].assetTypeDetailsList
			if(pageNumber==0){
			  results=[]
			}
			for(var i = 0; i < result.length; i++){
			  results.push(result[i]);
			}
			  _this.setState({
				result: results,
				pageNumber:1
			  })     
		  } 
		},"wfw")
	}


  changeMoney(val){
	  this.setState({
		  navindex:val,
		  pageNumber:0,
		  result:[]
	  })
	  var _this=this;
	  setTimeout(function(){
		  _this.getdate(0)
	  },600)	

  }
  onDateChange(e){
	var _this = this;
  	var createDateEnd = _this.state.createDateEnd
  	var evalue = e.detail.value
	  createDateEnd =evalue
	  _this.setState({
		  result:[],
		  createDateEnd:createDateEnd,
		  islisyr:1
		})
	setTimeout(function(){
		_this.getdate(0)
	},600)
	}
  
  render () {
	const result = this.state.result
	const resdata = this.state.resdata
	const money = this.state.money
	const appmark = this.state.appmark
    return (
      <View className='page'>
    		<ScrollView className='wdt-list' scrollY='true' onScrollToLower={this.loadMore.bind(this,'')}>
       			<View className='wdt-tj'>
       				<View className='wdt-li'>
						   <Text style={appmark=='xjzb'?'':'display:none'}>共享金</Text>
						   <Text style={appmark=='xjzb'?'display:none':''}>收益金</Text>
						   <View className='wdt-lis'>
							<Picker mode='date' onChange={this.onDateChange.bind(this)} fields='month'>
                			  <View className='picker'>{this.state.islisyr == 1 ?this.state.createDateEnd : '本月'}<Image className='xl' mode='widthFix' src={xl}></Image></View>
              				</Picker>
						</View>
					</View>
       				<View className='wdt-li02'>{money/100}</View>
       				<View className='wdt-li03'>
       					<Text className='wdt-r'>本月收入：{!resdata||resdata.length==0 ? '0':resdata.monthTotal.income/100}</Text>
       					<Text className='wdt-l'>本月支出：{!resdata||resdata.length==0 ? '0':resdata.monthTotal.expenditure/100}</Text>
       				</View>
       			</View>
       			<View className='gxh-oterh'>
	       			<View className='goods-order' onClick={this.opendetails.bind(this,'/pages/my/tx?type=BALANCE_GXJ')}>
	       				<Text className=''>提现申请</Text>
			        </View>
			        
			        <View className='goods-order'  onClick={this.opendetails.bind(this,'/pages/my/txlist')}>
			          <Text className=''>我的提现</Text>
			        </View>
			        <View className='goods-order'   onClick={this.opendetails.bind(this,'/pages/my/zrcapital')}>
			          <Text className=''>转让共享金</Text>
			         
			        </View>
			      </View> 
       			
       			<View className='wdt-mx'>
       				<View className='wdt-tit' style="padding-top:0">
       					<Text className={this.state.navindex==1?'tit-li activer':'tit-li'} onClick={this.changeMoney.bind(this,1)}>收入</Text>
       					<Text className={this.state.navindex==2?'tit-li activer':'tit-li'} onClick={this.changeMoney.bind(this,2)}>支出</Text>

       				</View>
       				
       				<View className='qun-mingxibo'>
					   <View className='nodate' style={!result||result.length==0?'':'display:none;'}>暂无数据</View>
					   {result.map((item,index)=>(
						   <View className='qun-mingxilist'>
						   <View className='qun-mngxicont'>
							 <View className='qun-mngxileft'>
							   <Text className='qun-minxizngs qun-reanao'>{item.note}</Text>
							   <Text className='qun-minxizngs qun-minxitit'>{CommonJs.FormatDate(item.createAt,3)}</Text>
							 </View>
							 <View className='qun-mngxiright'>
							   <Text style="margin-top:0" className={this.state.navindex==1?'qun-minxizngs qun-minxijine':'qun-minxizngs qun-minxijine qun-colors'}>{item.changeAmount/100}</Text>
							 </View>
						   </View>
					   </View>
					   ))}
	       				

			        </View>
       			</View>
       	</ScrollView>
      </View>
    )
  }
}

 